import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

public class Test {
    public static void main(String[] args) {
        //test1();
        test2();
    }
    public static void test1() {
        LinkedList<Integer> list = new LinkedList<>();
        list.add(1);
        list.add(2);
        list.addLast(10);
        list.addFirst(3);
        list.add(4);
        System.out.println(list);
        System.out.println("-------------");
        List<Integer> list1 = new LinkedList<>();
        list1.add(1);
        list1.add(12);
        list1.add(13);
        list1.add(14);
        list1.add(15);
        System.out.println(list1);
        System.out.println("-------------");
        List<Number> list2 = new LinkedList<>(list1);
        System.out.println(list2);
    }
    public static void test2() {
        LinkedList<Integer> list = new LinkedList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);
        list.add(6);
        System.out.println("--------直接sout输出--------");
        System.out.println(list);
        System.out.println("--------for循环遍历--------");
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i)+" ");
        }
        System.out.println();
        System.out.println("--------foreach循环遍历--------");
        for (Integer integer : list) {
            System.out.print(integer + " ");
        }
        System.out.println();
        System.out.println("--------迭代器正序输出1--------");
        Iterator<Integer> it = list.listIterator();
        while (it.hasNext()) {
            System.out.print(it.next()+" ");
        }
        System.out.println();
        System.out.println("--------迭代器正序输出2--------");
        ListIterator<Integer> its = list.listIterator();
        while (its.hasNext()) {
            System.out.print(its.next()+" ");
        }
        System.out.println();
        System.out.println("--------迭代器正序输出3（从指定下标位置输出）--------");
        ListIterator<Integer> itss = list.listIterator(2);
        while (itss.hasNext()) {
            System.out.print(itss.next()+" ");
        }
        System.out.println();
        System.out.println("--------迭代器逆序输出--------");
        ListIterator<Integer> reits = list.listIterator(list.size());
        while (reits.hasPrevious()) {
            System.out.print(reits.previous()+" ");
        }
    }
}
